<?php
class CoVppsController extends AppController {

	var $name = 'CoVpps';

	function index() {
		$this->CoVpp->recursive = 0;
		$this->set('coVpps', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid co vpp', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('coVpp', $this->CoVpp->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->CoVpp->create();
			if ($this->CoVpp->save($this->data)) {
				$this->Session->setFlash(__('The co vpp has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The co vpp could not be saved. Please, try again.', true));
			}
		}
		$bomons = $this->CoVpp->Bomon->find('list');
		$vanphongphams = $this->CoVpp->Vanphongpham->find('list');
		$this->set(compact('bomons', 'vanphongphams'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid co vpp', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->CoVpp->save($this->data)) {
				$this->Session->setFlash(__('The co vpp has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The co vpp could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->CoVpp->read(null, $id);
		}
		$bomons = $this->CoVpp->Bomon->find('list');
		$vanphongphams = $this->CoVpp->Vanphongpham->find('list');
		$this->set(compact('bomons', 'vanphongphams'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for co vpp', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->CoVpp->delete($id)) {
			$this->Session->setFlash(__('Co vpp deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Co vpp was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>